From: Ewan Mellor Date: Thu, 28 Dec 2006 12:26:29 +0000 (+0000) Subject: Implement network.get_VIFs. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15422^2~143 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=468611d262f2584a7ebd6681aa9b99e532f6bcf1;p=xen.git Implement network.get_VIFs. Signed-off-by: Ewan Mellor --- diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index d0cb8cfabb..6ea6ae075b 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -605,6 +605,16 @@ class XendDomain: finally: self.domains_lock.release() + def get_all_vms(self): + self.domains_lock.acquire() + try: + result = self.domains.values() + result += [x for x in self.managed_domains.values() if + x not in result] + return result + finally: + self.domains_lock.release() + def get_vm_by_uuid(self, vm_uuid): self.domains_lock.acquire() try: diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index e66bf89915..a92b706986 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -1967,8 +1967,12 @@ class XendDomainInfo: config['device'] = 'eth%d' % devid else: config['device'] = '' - - config['network'] = '' # Invalid for Xend + + if not config.has_key('network'): + config['network'] = \ + XendNode.instance().bridge_to_network( + config.get('bridge')).uuid + config['MTU'] = 1500 # TODO config['io_read_kbs'] = 0.0 config['io_write_kbs'] = 0.0 diff --git a/tools/python/xen/xend/XendNetwork.py b/tools/python/xen/xend/XendNetwork.py index 42d421d5eb..be0d5cedd5 100644 --- a/tools/python/xen/xend/XendNetwork.py +++ b/tools/python/xen/xend/XendNetwork.py @@ -21,6 +21,7 @@ import re import struct import socket +import XendDomain import XendNode from XendLogging import log @@ -83,7 +84,15 @@ class XendNetwork: XendNode.instance().save_networks() def get_VIF_UUIDs(self): - return [] + result = [] + vms = XendDomain.instance().get_all_vms() + for vm in vms: + vifs = vm.get_vifs() + for vif in vifs: + vif_cfg = vm.get_dev_xenapi_config('vif', vif) + if vif_cfg['network'] == self.uuid: + result.append(vif) + return result def get_PIF_UUIDs(self): return [x.uuid for x in XendNode.instance().pifs.values() diff --git a/tools/python/xen/xend/XendNode.py b/tools/python/xen/xend/XendNode.py index 1d900f124e..ccbcdd30fb 100644 --- a/tools/python/xen/xend/XendNode.py +++ b/tools/python/xen/xend/XendNode.py @@ -289,6 +289,22 @@ class XendNode: def get_network(self, network_ref): return self.networks[network_ref] + def bridge_to_network(self, bridge): + if not bridge: + rc, bridge = commands.getstatusoutput( + 'brctl show | cut -d "\n" -f 2 | cut -f 1') + if rc != 0 or not bridge: + raise Exception( + 'Could not find default bridge, and none was specified') + + bridges = Brctl.get_state() + if bridge not in bridges: + raise Exception('Bridge %s is not up' % bridge) + for pif in self.pifs.values(): + if pif.interface_name() in bridges[bridge]: + return pif.network + raise Exception('Bridge %s is not connected to a network' % bridge) + # # Getting host information. diff --git a/tools/python/xen/xend/XendPIF.py b/tools/python/xen/xend/XendPIF.py index b4b0e973be..aea03e0b16 100644 --- a/tools/python/xen/xend/XendPIF.py +++ b/tools/python/xen/xend/XendPIF.py @@ -134,7 +134,7 @@ class XendPIF: def refresh(self, bridges): - ifname = self._ifname() + ifname = self.interface_name() rc, _ = _cmd('ip link show %s', ifname) if rc != 0: # Interface does not exist. If it's a physical interface, then @@ -172,7 +172,7 @@ class XendPIF: log.info('Added network interface %s to bridge %s', ifname, brname) - def _ifname(self): + def interface_name(self): if self.vlan: return '%s.%s' % (self.name, self.vlan) else: